﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp.AspNetCore.Mvc;
using Volo.Abp.Domain.Repositories;
using YAKEJI.Xaf.DataDictionaries;

namespace YAPACS.RisServer.Controllers;
[Authorize]
public class DataDictController : AbpControllerBase
{
    private readonly IRepository<DataDictItem, Guid> _dataDictItemRepository;

    public DataDictController(IRepository<DataDictItem, Guid> dataDictItemRepository)
    {
        _dataDictItemRepository = dataDictItemRepository;
    }

    [HttpGet("/api/get-data-dict-by-name/{name}")]
    public async Task<IActionResult> GetData(string name)
    {
        // 民族
        var dataDictItems = await _dataDictItemRepository.GetListAsync(e => e.DataDictionary.Name == name);
        var items = dataDictItems.OrderBy(e=>e.Order).ThenBy(e=>e.CreationTime).Select(e => new
        {
            Label = e.Name,
            Value = e.Id
        });
        return Ok(items);
    }
}
